﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using xycn.ILogHelper;

namespace xycn.pluginsupport.BaseHelperPlugins
{
    public static class LogHelper
    {
        private static ILogHelper.ILogHelper logHelper = null;

        /// <summary>
        /// 添加日志插件接口
        /// </summary>
        /// <param name="name"></param>
        /// <param name="dbfactory"></param>
        /// <returns></returns>
        public static int Init(IPluginFactory.IPluginFactory logfactory)
        {
            if (logfactory == null)
                return -1;

            logHelper = (ILogHelper.ILogHelper)logfactory.CreatePlugin();
            return 0;
        }
        
        /// <summary>
        /// 普通信息
        /// </summary>
        /// <param name="msg"></param>
        public static void Info(string msg, bool is_debug)
        {
            if (logHelper == null)
            {
                Console.WriteLine(msg);
                return;
            }

            logHelper.Info(msg, is_debug);

        }

        /// <summary>
        /// 普通信息
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="repmsg"></param>
        /// <param name="resmsg"></param>
        public static void Info(string msg, object repmsg = null, 
            object resmsg = null, bool is_debug = true)
        {
            if (logHelper == null)
            {
                Console.WriteLine(msg);
                return;
            }

            logHelper.Info(msg, repmsg, resmsg, is_debug);
        }

        /// <summary>
        /// 警告信息
        /// </summary>
        /// <param name="msg"></param>
        public static void Warn(string msg, bool is_debug)
        {
            if (logHelper == null)
            {
                Console.WriteLine(msg);
                return;
            }

            logHelper.Warn(msg, is_debug);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="repmsg"></param>
        /// <param name="resmsg"></param>
        public static void Warn(string msg, object repmsg = null, 
            object resmsg = null, bool is_debug = true)
        {
            if (logHelper == null)
            {
                Console.WriteLine(msg);
                return;
            }

            logHelper.Warn(msg, repmsg, resmsg, is_debug);
        }

        /// <summary>
        /// 普通信息
        /// </summary>
        /// <param name="msg"></param>
        public static void Error(string msg, bool is_debug = true)
        {
            if (logHelper == null)
            {
                Console.WriteLine(msg);
                return;
            }

            logHelper.Error(msg, is_debug);

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="repmsg"></param>
        /// <param name="resmsg"></param>
        public static void Error(string msg, object repmsg = null, 
            object resmsg = null, bool is_debug = true)
        {
            if (logHelper == null)
            {
                Console.WriteLine(msg);
                return;
            }

            logHelper.Error(msg, repmsg, resmsg, is_debug);
        }

        /// <summary>
        /// 错误信息
        /// </summary>
        /// <param name="ex"></param>
        /// <param name="remark"></param>
        /// <param name="reqdata"></param>
        public static void Error(Exception ex, string remark, 
            object reqdata = null, bool is_debug = true)
        {
            if (logHelper == null)
            {
                Console.WriteLine(ex.Message);
                return;
            }
            logHelper.Error(ex, remark,reqdata, is_debug);

        }

        /// <summary>
        /// 错误信息
        /// </summary>
        /// <param name="ex"></param>
        /// <param name="remark"></param>
        /// <param name="reqdata"></param>
        public static void Exception(Exception ex, string remark, 
            object reqdata = null, object resdata = null, bool is_debug = true)
        {
            if (logHelper == null)
            {
                Console.WriteLine(ex.Message);
                return;
            }
            logHelper.Exception(ex, remark, reqdata, resdata, is_debug);

        }
    }
}
